package cn.tedu.ivos.vehicle.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleQuery;
import cn.tedu.ivos.vehicle.pojo.dto.VehicleSaveParam;
import cn.tedu.ivos.vehicle.pojo.vo.VehicleVO;
import cn.tedu.ivos.vehicle.service.VehicleService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@RequestMapping("/v1/vehicle")
public class VehicleController {
    @Autowired
    VehicleService vehicleService;
    @GetMapping("select")
    public JsonResult select(VehicleQuery vehicleQuery){
        log.debug("车辆查询:vehicleQuery={}", vehicleQuery);
        List<VehicleVO>list =vehicleService.selectVehicle(vehicleQuery);
        return JsonResult.ok(list);
    }
    @PostMapping("save")
    public JsonResult saveVehicle(VehicleSaveParam vehicleSaveParam){
        log.debug("车辆保存:vehicleQuery={}", vehicleSaveParam);
        vehicleService.saveVehicle(vehicleSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteVehicle(@PathVariable Long id){
        log.debug("车辆删除:id={}", id);
        vehicleService.deleteVehicle(id);
        return JsonResult.ok();
    }
    @PostMapping("unbind/{id}")
    public JsonResult unbind(@PathVariable Long id){
        log.debug("车辆解绑:id={}", id);
        vehicleService.unbind(id);
        return JsonResult.ok();
    }
    @PostMapping("bind/{geoId}/{id}")
    public JsonResult bind(@PathVariable Long geoId,@PathVariable Long id){
        log.debug("车辆绑定:geoId={},id={}", geoId,id);
        vehicleService.bind(geoId,id);
        return JsonResult.ok();
    }
}
